package com.jintoufs.web.action.sys;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jintoufs.dao.QueryFilters;
import com.jintoufs.domain.constants.Constants;
import com.jintoufs.domain.images.Placard;
import com.jintoufs.domain.sys.Dictionary;
import com.jintoufs.logAnnotation.SystemControllerLog;
import com.jintoufs.service.image.PlacardService;
import com.jintoufs.service.sys.DictionaryService;
import com.jintoufs.util.valid.ValidUtil;
import com.jintoufs.web.action.support.JqgridPage;
import com.jintoufs.web.action.support.SupportAction;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhaokai
 * @Description: 系统字典
 * @date 2016年2月19日 下午4:26:36
 */
@Controller
@Scope("prototype")
@RequestMapping("/setting")
public class SettingAction extends SupportAction {

    @Resource
    private DictionaryService dictionaryService;

    @Resource
    private PlacardService placardService;

    @RequestMapping("/input")
    public String input(Model model) {
        List<Dictionary> list = dictionaryService.getDicByKeyNo(Constants.PLACARD_HOTEL);
        List<Dictionary> list2 = dictionaryService.getDicByKeyNo(Constants.PLACARD_ROUTE);
        if (!ValidUtil.isEmpty(list)) {
            model.addAttribute("placardHotel", list.get(0).getKeyValue());
        }
        if (!ValidUtil.isEmpty(list2)) {
            model.addAttribute("placardRoute", list2.get(0).getKeyValue());
        }
        return "setting/input";
    }


    @RequestMapping("/update")
    @SystemControllerLog(description = "设置海报")
    @ResponseBody
    public AjaxMsg update(String placardHotel, String placardRoute) {
        AjaxMsg ajaxMsg = new AjaxMsg();

        List<Dictionary> list = dictionaryService.getDicByKeyNo(Constants.PLACARD_HOTEL);
        List<Dictionary> list2 = dictionaryService.getDicByKeyNo(Constants.PLACARD_ROUTE);
        if (!ValidUtil.isEmpty(list)) {
            Dictionary dictionary = list.get(0);
            dictionary.setKeyValue(placardHotel);
            dictionaryService.update(dictionary);
        }
        if (!ValidUtil.isEmpty(list2)) {
            Dictionary dictionary = list2.get(0);
            dictionary.setKeyValue(placardRoute);
            dictionaryService.update(dictionary);
        }
        ajaxMsg.setCode("200");
        ajaxMsg.setMessage("更新成功");
        return ajaxMsg;
    }


}
